import java.util.Arrays;

/**
 * Created with Intellij IDEA.
 * Description;
 * User:墨琦
 * Data:2023-04-10
 * Time:9:00
 */
public class Work <T>{

    private Object[] elem=new Object[10];
    public int size;
    public  Work()
    {
    }
    public void isFull()
    {
        if(this.size== elem.length)
        {
             elem= Arrays.copyOf(elem,2*elem.length);
        }

    }
    //添加值
    public void add(T sum)
    {
        isFull();
        elem[size]=sum;
        size++;
    }
    public T get(int pos)
    {
        return (T)elem[pos];
    }
    //删除下标值
    public void removeSubscript(int sum) {
        int i=sum-1;
        while(i<size-1) {
        elem[i]=elem[i+1];
        i++;
        }
        elem[i]=0;
        size--;
    }
    //删除值
    public void deletesum(T sum)
    {
        int i=0;
        if(sum instanceof Integer)
        {
            for(;i<size;i++)
            {
                if(elem[i]==sum)
                {
                    while(i<size-1)
                    {
                        elem[i]=elem[i+1];
                        i++;
                    }
                    break;
                }
            }
        }
        else{
            for(;i<size;i++)
            {
                if(elem[i].equals(sum))
                {
                    while(i<size-1)
                    {
                        elem[i]=elem[i+1];
                        i++;
                    }
                    break;
                }
            }
        }
       size--;
    }
    //展示
    public void show()
    {
        for(int i=0;i<size;i++)
        {
            System.out.print((T)elem[i]+" ");
        }
        System.out.println();
    }
    //查找
    public int find(T sum)
    {
        int i=0;
        if(sum instanceof Integer)
        {
            for(;i<size;i++)
            {
                if(elem[i]==sum) {
                    return i;
                }
            }
        }
        else  for(;i<size;i++)
        {
            if(elem[i].equals(sum)) {
                return i;
            }
        }
         return -1;
    }
    //

}
